<div id="tb<?php echo $uniqid;?>" style="padding:5px">
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td><a href="javascript:void(0);" onclick="iconAdd();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-tianjia1"></i><span class="l-btn-text">增加</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="iconEdit();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">编辑</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="iconDelete();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">删除</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="iconReload();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
            <td>&nbsp&nbsp;<input id="iconKeywords" style="width:100px" type="text"
                                  class="easyui-input textbox"></td>
            <td><a href="javascript:void(0);" onclick="iconSearch();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
        </tr>
        </tbody>
    </table>
</div>
<div class="con" onselectstart="return false;" style="-moz-user-select:none;">
    <table id="icon"></table>
</div>
<div id="icondlg" class="easyui-dialog" style="width:720px; height:460px;" title="信息框" closed="true"></div>
<script>
    var iconAdd = function () {
        $("#icondlg").dialog({
            title: '新增信息',
            closed: false,
            width: 740,
            height: 600,
            cache: false,
            href: '/admin/icon/add',
            modal: true,
            buttons: [{
                text: '保存',
                id: 'iconaddsubmit',
                iconCls: 'icon-ok',
            }, {
                text: '关闭',
                iconCls: 'icon-no',
                handler: function () {
                    $("#icondlg").dialog('close');
                }
            }]
        });
    };
    var iconEdit = function () {
        var row = $('#icon').datagrid('getSelected');
        if (row) {
            $("#icondlg").dialog({
                title: '编辑信息',
                closed: false,
                width: 740,
                height: 600,
                cache: false,
                href: '/admin/icon/edit?id=' + row.id,
                modal: true,
                buttons: [{
                    text: '保存',
                    id: 'iconeditsubmit',
                    iconCls: 'icon-ok',
                }, {
                    text: '关闭',
                    iconCls: 'icon-no',
                    handler: function () {
                        $("#icondlg").dialog('close');
                    }
                }]
            });
        } else {
            $.messager.alert('提示', '请先选择要编辑的行！', 'warning');
        }
    };
    var iconDelete = function () {
        var row = $('#icon').datagrid('getSelected');
        if (row) {
            $.messager.confirm('提示', '确定删除吗？', function (r) {
                if (r == true) {
                    $.messager.progress();
                    $.post('/admin/icon/delete', {id: row.id}, function (data) {
                        $.messager.progress('close');
                        if (data.ret == 0) {
                            $.messager.show({
                                title: '提示',
                                msg: data.msg,
                                timeout: 3000,
                                showType: 'slide'
                            });
                            iconreload();
                        } else {
                            $.messager.alert('提示', data.msg, 'warning');
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.alert('提示', '请先选择要删除的行！', 'warning');
        }
    };
    var iconReload = function () {
        $("#icon").treegrid('reload');
    };
    var iconSearch = function () {
        var height = $(window).height() - $(".top").height() - 46;
        var width = $(window).width() - $(".leftmenu").width() - 13;
        $("#icon").treegrid({
            title: '菜单图标',
            width: width,
            height: height,//高度
            singleSelect: true,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: true,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 10,
            pageList: [10, 15, 20, 25],
            method: 'post',
            sortName: 'sortorder',
            sortOrder: 'desc',
            idField: 'id',
            treeField: 'title',
            url: '/admin/icon/get',
            queryParams: {keywords: $('#categorieskeywords').val()},
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: false,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            showFooter: true,

            columns: [[
                {field: 'name', title: '名称', width: '20%'},
                {field: 'class', title: '类名', width: '20%'},
                {field: 'classView', title: '展示', align:'center', width: '10%', formatter: function (value, rowData, rowIndex) {
                        if (value != '') {
                            return '<i style="font-size: 22px;color: #FF6666" class="iconfont '+rowData.class+'"></i>';
                        }
                    }},
                {field: 'sortorder', title: '排序', width: '10%', sortable: true},
                {field: 'created_at', title: '创建时间', width: '20%'},
            ]],
            onDblClickRow: function (index, field) {
                iconEdit();
            },
            onLoadSuccess: function (row, data) {
                $.each(data, function (i, val) {
                    $('#icon').treegrid('collapseAll', data[i].id)
                })
            }
        });
    };
    function category_update_status(id, status) {
        $.post('/admin/icon/updateStatus', {id: id, status:status}, function (data) {
            if (data.ret == 0) {
                $.messager.show({
                    title: '提示',
                    msg: data.msg,
                    timeout: 3000,
                    showType: 'slide'
                });
                $("#icon").treegrid('reload');
            } else {
                $.messager.alert('提示', data.msg, 'warning');
            }
        }, 'json');
    };
    iconSearch();
</script>
